package com.example.loginlib

import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.view.Gravity
import android.view.View
import androidx.appcompat.widget.ListPopupWindow
import com.example.baselib.constants.MyConstants
import com.example.baselib.dialog.BaseDialogFragment
import huaan.com.mvvmdemo.http.RetrofitClient
import kotlinx.android.synthetic.main.activity_choose_url.*
import kotlinx.android.synthetic.main.activity_choose_url.view.*

class ChooseUrlDialog : BaseDialogFragment() {
    override fun getContentLayout(): Int {
        return R.layout.activity_choose_url
    }

    override fun initView(view: View) {
        view.url_group.check(if(MyConstants.isTest)view.test_url_rtn.id else view.base_url_rtn.id)
        view.url_group.setOnCheckedChangeListener { _, checkedId -> MyConstants.isTest=
            checkedId != base_url_rtn.id
        }
        view.set_url_btn.setOnClickListener {
            RetrofitClient.setBaseUrl()
            dismiss() }
    }

    override fun initData() {

    }

    override fun setDialogStyle() {
        //无标题
        dialog?.requestWindowFeature(STYLE_NO_TITLE)
        //点击外部不消失
        dialog?.setCanceledOnTouchOutside(false)
        //设置 样式
        dialog?.window?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
        dialog?.window?.decorView?.setPadding(0, 0, 0, 0)
        dialog?.window?.attributes?.width= ListPopupWindow.WRAP_CONTENT
        dialog?.window?.attributes?.height= ListPopupWindow.WRAP_CONTENT
        dialog?.window?.attributes?.gravity= Gravity.CENTER
    }

}
